﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();



            string param = "Name=Tester&CoordinateX=100&CoordinateY=200";
            //string param = "hl=zh-CN&newwindow=1";
            byte[] bs = Encoding.ASCII.GetBytes(param);

            //HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/index.php");
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://srcar.sinaapp.com/index.php");
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = bs.Length;

            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
            }

            HttpWebRequest reqGet = (HttpWebRequest)HttpWebRequest.Create("http://srcar.sinaapp.com/index.php");
            using (WebResponse wr = reqGet.GetResponse())
            {
                Stream receiveStream = wr.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
                // Pipes the stream to a higher level stream reader with the required encoding format. 
                StreamReader readStream = new StreamReader(receiveStream, encode);

                Char[] read = new Char[256];
                int count = readStream.Read(read, 0, 256);
                StringBuilder sb = new StringBuilder("");
                while (count > 0)
                {
                    String readstr = new String(read, 0, count);
                    sb.Append(readstr);
                    count = readStream.Read(read, 0, 256);
                }

                webBrowser1.DocumentText = sb.ToString();

                wr.Close();
                readStream.Close();
            } 

        }
    }
}
